package mk.com.ldm.corepoint.implementation.shared;

import java.io.Serializable;
import java.util.ArrayList;


@SuppressWarnings("serial")
public class DataBaseObject implements Serializable{
	private String dbName = "", columnAlias = "";
	private boolean needsSingleQuotes = false, conditions = false, display = true, filter = true;
	private String value = "";
	private ArrayList<String> conditionValues = new ArrayList<String>();
	private String condOperator = "=";
	public ArrayList<Foreign> foreign = new ArrayList<Foreign>();
	
	public DataBaseObject(){}
	
	/**
	 * Constructor best used for select queries
	 * 
	 * @param dbName
	 * @param needsSingleQuotes
	 * @param conditions
	 * @param conditionValue
	 * @param foreign
	 */
	public DataBaseObject(String dbName, boolean needsSingleQuotes, boolean conditions, ArrayList<String> conditionValues, ArrayList<Foreign> foreign){
		this.dbName = dbName;
		this.needsSingleQuotes = needsSingleQuotes;
		this.conditions = conditions;
		this.conditionValues = conditionValues;
		this.foreign = foreign;
	}
	
	/**
	 * Constructor best used for simple selects without joins
	 * 
	 * @param dbName
	 * @param needsSingleQuotes
	 * @param conditions
	 * @param conditionValue
	 */
	public DataBaseObject(String dbName, boolean needsSingleQuotes, boolean conditions, ArrayList<String> conditionValues){
		this.dbName = dbName;
		this.needsSingleQuotes = needsSingleQuotes;
		this.conditions = conditions;
		this.conditionValues = conditionValues;
	}
	
	/**
	 * Constructor best used for very simple selects without any conditions
	 * 
	 * @param dbName
	 * @param needsSingleQuotes
	 */
	public DataBaseObject(String dbName, boolean needsSingleQuotes){
		this.dbName = dbName;
		this.needsSingleQuotes = needsSingleQuotes;
	}
	
	/**
	 * Constructor best used for join selects without any conditions
	 * 
	 * @param dbName
	 * @param needsSingleQuotes
	 * @param foreign
	 */
	public DataBaseObject(String dbName, boolean needsSingleQuotes, ArrayList<Foreign> foreign){
		this.dbName = dbName;
		this.needsSingleQuotes = needsSingleQuotes;
		this.foreign = foreign;
	}
	
	/**
	 * Constructor best used for insert queries
	 * 
	 * @param dbName
	 * @param needsSingleQuotes
	 * @param value
	 */
	public DataBaseObject(String dbName, boolean needsSingleQuotes, String value){
		this.dbName = dbName;
		this.needsSingleQuotes = needsSingleQuotes;
		this.value = value;
	}
	
	/**
	 * Constructor best used for update queries
	 * 
	 * @param dbName
	 * @param needsSingleQuotes
	 * @param value
	 * @param conditions
	 * @param conditionValue
	 */
	public DataBaseObject(String dbName, boolean needsSingleQuotes, String value, boolean conditions, ArrayList<String> conditionValues, String type) {
		this.dbName = dbName;
		this.needsSingleQuotes = needsSingleQuotes;
		this.value = value;
		this.conditions = conditions;
		this.conditionValues = conditionValues;
		if(type.equals("character varying")||type.equals("datetime")){
			this.needsSingleQuotes = true;
		}
		if(type.equals("serial")||type.equals("integer")){
			this.needsSingleQuotes = false;
		}
	}
	
	/**
	 * General constructor containing all parameters of the class
	 * 
	 * @param dbName
	 * @param needsSingleQuotes
	 * @param display
	 * @param value
	 * @param conditions
	 * @param conditionValue
	 * @param condOperator
	 * @param foreign
	 */
	

	public String getDbName() {
		return dbName;
	}
	
	public DataBaseObject(String dbName, String columnAlias,
			boolean needsSingleQuotes, boolean conditions, boolean display,
			boolean filter, String value, ArrayList<String> conditionValues,
			String condOperator, ArrayList<Foreign> foreign) {
		super();
		this.dbName = dbName;
		this.columnAlias = columnAlias;
		this.needsSingleQuotes = needsSingleQuotes;
		this.conditions = conditions;
		this.display = display;
		this.filter = filter;
		this.value = value;
		this.conditionValues = conditionValues;
		this.condOperator = condOperator;
		this.foreign = foreign;
	}

	public void setDbName(String dbName) {
		this.dbName = dbName;
	}
	
	public boolean getNeedsSingleQuotes() {
		return needsSingleQuotes;
	}

	public void setNeedsSingleQuotes(boolean needsSingleQuotes) {
		this.needsSingleQuotes = needsSingleQuotes;
	}

	public String getValue() {
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}

	public boolean isConditions() {
		return conditions;
	}

	public void setConditions(boolean conditions) {
		this.conditions = conditions;
	}

	public ArrayList<String> getConditionValues() {
		return conditionValues;
	}

	public void setConditionValues(ArrayList<String> conditionValues) {
		this.conditionValues = conditionValues;
	}
	
	public void addConditionValue(String value){
		conditionValues.add(value);
	}
	
	public void removeConditionValue(int index){
		conditionValues.remove(index);
	}
	
	public void removeConditionValue(String value){
		conditionValues.remove(value);
	}

	public boolean isDisplay() {
		return display;
	}

	public void setDisplay(boolean display) {
		this.display = display;
	}

	public String getCondOperator() {
		return condOperator;
	}

	public void setCondOperator(String condOperator) {
		this.condOperator = condOperator;
	}

	public boolean isFilter() {
		return filter;
	}

	public void setFilter(boolean filter) {
		this.filter = filter;
	}

	public String getColumnAlias() {
		return columnAlias;
	}

	public void setColumnAlias(String columnAlias) {
		this.columnAlias = columnAlias;
	}

	public DataBaseObject clone(){
		return new DataBaseObject(dbName, columnAlias, needsSingleQuotes, conditions, display, filter, value, conditionValues, condOperator, foreign);
	}
}
